<li><a class="reference internal" href="#how-do-i-run-a-python-program-under-windows" id="id1">1 How do I run a Python program under Windows?</a></li>
<li><a class="reference internal" href="#how-do-i-make-python-scripts-executable" id="id2">2 How do I make python scripts executable?</a></li>
<li><a class="reference internal" href="#why-does-python-sometimes-take-so-long-to-start" id="id3">3 Why does Python sometimes take so long to start?</a></li>
<li><a class="reference internal" href="#where-is-freeze-for-windows" id="id4">4 Where is Freeze for Windows?</a></li>
<li><a class="reference internal" href="#is-a-pyd-file-the-same-as-a-dll" id="id5">5 Is a <tt class="docutils literal"><span class="pre">*.pyd</span></tt> file the same as a DLL?</a></li>
<li><a class="reference internal" href="#how-can-i-embed-python-into-a-windows-application" id="id6">6 How can I embed Python into a Windows application?</a></li>
<li><a class="reference internal" href="#how-do-i-use-python-for-cgi" id="id7">7 How do I use Python for CGI?</a></li>
<li><a class="reference internal" href="#how-do-i-keep-editors-from-inserting-tabs-into-my-python-source" id="id8">8 How do I keep editors from inserting tabs into my Python source?</a></li>
<li><a class="reference internal" href="#how-do-i-check-for-a-keypress-without-blocking" id="id9">9 How do I check for a keypress without blocking?</a></li>
<li><a class="reference internal" href="#how-do-i-emulate-os-kill-in-windows" id="id10">10 How do I emulate os.kill() in Windows?</a></li>
<li><a class="reference internal" href="#why-does-os-path-isdir-fail-on-nt-shared-directories" id="id11">11 Why does os.path.isdir() fail on NT shared directories?</a></li>
<li><a class="reference internal" href="#cgi-py-or-other-cgi-programming-doesn-t-work-sometimes-on-nt-or-win95" id="id12">12 cgi.py (or other CGI programming) doesn't work sometimes on NT or win95!</a></li>
<li><a class="reference internal" href="#why-doesn-t-os-popen-work-in-pythonwin-on-nt" id="id13">13 Why doesn't os.popen() work in PythonWin on NT?</a></li>
<li><a class="reference internal" href="#why-doesn-t-os-popen-win32pipe-popen-work-on-win9x" id="id14">14 Why doesn't os.popen()/win32pipe.popen() work on Win9x?</a></li>
<li><a class="reference internal" href="#pyrun-simplefile-crashes-on-windows-but-not-on-unix-why" id="id15">15 PyRun_SimpleFile() crashes on Windows but not on Unix; why?</a></li>
<li><a class="reference internal" href="#importing-tkinter-fails-on-windows-95-98-why" id="id16">16 Importing _tkinter fails on Windows 95/98: why?</a></li>
<li><a class="reference internal" href="#how-do-i-extract-the-downloaded-documentation-on-windows" id="id17">17 How do I extract the downloaded documentation on Windows?</a></li>
<li><a class="reference internal" href="#warning-about-ctl3d32-version-from-installer" id="id19">19 Warning about CTL3D32 version from installer</a></li>
<h1><a class="toc-backref" href="#id1">1 How do I run a Python program under Windows?</a></h1>
<p>This is not necessarily a straightforward question. If you are already
familiar with running programs from the Windows command line then
everything will seem obvious; otherwise, you might need a little more
guidance. There are also differences between Windows 95, 98, NT, ME,
2000 and XP which can add to the confusion.</p>
<p>Unless you use some sort of integrated development environment,
you will end up <em>typing</em> Windows commands into what is variously referred
to as a "DOS window" or "Command prompt window". Usually you can
create such a window from your Start menu; under Windows 2000
the menu selection is
"Start | Programs | Accessories | Command Prompt". You should be
able to recognize when you have started such a window because you will
see a Windows "command prompt", which usually looks like this:</p>
<pre class="literal-block">
C:\>
</pre>
<p>The letter may be different, and there might be other things after it,
so you might just as easily see something like:</p>
<pre class="literal-block">
D:\Steve\Projects\Python>
</pre>
<p>depending on how your computer has been set up and what else you have
recently done with it. Once you have started such a window, you are
well on the way to running Python programs.</p>
<p>You need to realize that your Python scripts have to be processed by
another program called the Python interpreter. The
interpreter reads your script, compiles it into bytecodes, and then executes the bytecodes to run your
program. So, how do you arrange for the interpreter to handle your
Python?</p>
<p>First, you need to make sure that your command window recognises the
word "python" as an instruction to start the interpreter. If you have
opened a command window, you should try entering the command <tt class="docutils literal"><span class="pre">python</span></tt>
and hitting return. You should then see something like:</p>
<pre class="literal-block">
Python 2.2 (#28, Dec 21 2001, 12:21:22) [MSC 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
</pre>
<p>You have started the interpreter in "interactive mode". That means you
can enter Python statements or expressions interactively and have them
executed or evaluated while you wait. This is one of Python's
strongest features. Check it by entering a few expressions of your
choice and seeing the results:</p>
<pre class="literal-block">
>>> print "Hello"
Hello
>>> "Hello" * 3
HelloHelloHello
</pre>
<p>Many people use the interactive mode as a convenient yet highly
programmable calculator.
When you want to end your interactive Python session, hold the Ctrl
key down while you enter a Z, then hit the "Enter" key to get back to
your Windows command prompt.</p>
<p>You may also find that you have a
Start-menu entry such as "Start | Programs | Python 2.2 | Python
(command line)" that results in you seeing the <tt class="docutils literal"><span class="pre">>>></span></tt> prompt in a new
window. If so, the window will disappear after you enter the
Ctrl-Z character; Windows is running a single "python" command in the window,
and closes it when you terminate the interpreter.</p>
<p>If the <tt class="docutils literal"><span class="pre">python</span></tt> command, instead of displaying the interpreter
prompt <tt class="docutils literal"><span class="pre">>>></span></tt>, gives you a message like:</p>
<pre class="literal-block">
'python' is not recognized as an internal or external command,
operable program or batch file.
</pre>
<p>or:</p>
<pre class="literal-block">
Bad command or filename
</pre>
<p>then you need to make sure that your computer knows where to find the
Python interpreter. To do this you will have to modify a setting
called PATH, which is a list of directories where Windows
will look for programs. You should arrange for Python's
installation directory to be added to the PATH of every command window
as it starts. If you installed Python fairly recently then the command</p>
<pre class="literal-block">
dir C:\py*
</pre>
<p>will probably tell you where it is installed; the usual location is
something like <tt class="docutils literal"><span class="pre">C:\Python23</span></tt>. Otherwise you will be reduced to a search of your
whole disk ... use "Tools | Find"
or hit the "Search" button and look for "python.exe". Supposing you
discover that Python is installed in the <tt class="docutils literal"><span class="pre">C:\Python23</span></tt> directory (the
default at the time of writing), you should make sure that
entering the command</p>
<pre class="literal-block">
c:\Python23\python
</pre>
<p>starts up the interpreter as above (and don't forget you'll need a
"CTRL-Z" and an "Enter" to get out of it). Once you have verified the
directory, you need to add it to the start-up routines your computer
goes through. For older versions of Windows the easiest way to do
this is to edit the <tt class="docutils literal"><span class="pre">C:\AUTOEXEC.BAT</span></tt> file. You would want to add a line
like the following to <tt class="docutils literal"><span class="pre">AUTOEXEC.BAT</span></tt>:</p>
<pre class="literal-block">
PATH C:\Python23;%PATH%
</pre>
<p>For Windows NT, 2000 and (I assume) XP, you will need to add a string
such as</p>
<pre class="literal-block">
;C:\Python23
</pre>
<p>to the current setting for the PATH environment variable, which you
will find in the properties window of "My Computer" under the
"Advanced" tab. Note that if you have sufficient privilege you might
get a choice of installing the settings either for the Current User or
for System. The latter is preferred if you want everybody to be able
to run Python on the machine.</p>
<p>If you aren't confident doing any of these manipulations yourself, ask
for help! At this stage you may want to reboot your system
to make absolutely sure the new setting has taken effect. You probably
won't need to reboot for Windows NT, XP or 2000. You can also avoid it in
earlier versions by editing the file <tt class="docutils literal"><span class="pre">C:\WINDOWS\COMMAND\CMDINIT.BAT</span></tt>
instead of <tt class="docutils literal"><span class="pre">AUTOEXEC.BAT</span></tt>.</p>
<p>You should now be able to start a new command window, enter <tt class="docutils literal"><span class="pre">python</span></tt>
at the <tt class="docutils literal"><span class="pre">C:></span></tt> (or whatever) prompt, and see the <tt class="docutils literal"><span class="pre">>>></span></tt> prompt that
indicates the Python interpreter is reading interactive commands.</p>
<p>Let's suppose you have a program called <tt class="docutils literal"><span class="pre">pytest.py</span></tt> in directory
<tt class="docutils literal"><span class="pre">C:\Steve\Projects\Python</span></tt>. A session to run that program might look
like this:</p>
<pre class="literal-block">
C:\> cd \Steve\Projects\Python
C:\Steve\Projects\Python> python pytest.py
</pre>
<p>Because you added a file name to the command to start the interpreter,
when it starts up it reads the Python script in the named file,
compiles it, executes it, and terminates, so you see another <tt class="docutils literal"><span class="pre">C:\></span></tt>
prompt. You might also have entered</p>
<pre class="literal-block">
C:\> python \Steve\Projects\Python\pytest.py
</pre>
<p>if you hadn't wanted to change your current directory.</p>
<p>Under NT, 2000 and XP you may well find that the installation process
has also arranged that the command <tt class="docutils literal"><span class="pre">pytest.py</span></tt>
<h1><a class="toc-backref" href="#id4">4 Where is Freeze for Windows?</a></h1>
<p>"Freeze" is a program that allows you to ship a Python program
as a single stand-alone executable file. It is <em>not</em> a compiler;
your programs don't run any faster, but they are more easily
distributable, at least to platforms with the same OS and CPU. Read the
README file of the freeze program for more disclaimers.</p>
<p>You can use freeze on Windows, but you must download the source
tree (see <a class="reference external" href="http://www.python.org/download/download_source.html">http://www.python.org/download/download_source.html</a>).
The freeze program is in the <tt class="docutils literal"><span class="pre">Tools\freeze</span></tt> subdirectory of the source
tree.</p>
<p>You need the Microsoft VC++ compiler, and you probably need to build
Python. The required project files are in the PCbuild directory.</p>
provided "scripts" is an "executable" directory for your server (which
it usually is by default).
The "-u" flag specifies unbuffered and binary mode for stdin - needed when working with binary data.</p>
<p>In addition, it is recommended that using
".py" may not be a good idea for the file extensions when used in this
context (you might want to reserve <tt class="docutils literal"><span class="pre">*.py</span></tt> for support modules and
use <tt class="docutils literal"><span class="pre">*.cgi</span></tt> or <tt class="docutils literal"><span class="pre">*.cgp</span></tt> for "main program" scripts).</p>
<p>In order to set up Internet Information Services 5 to use Python for CGI processing, please see the following links:</p>